/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.integral.core.handler;

import com.fulihui.integral.core.enums.ISChannelType;
import com.fulihui.integral.core.request.ISUserBehaviorReq;
import com.fulihui.mscore.api.MessageService;
import com.fulihui.mscore.request.MsgCreateRequest;
import org.near.servicesupport.request.RequestBuilder;
import org.near.servicesupport.result.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * @author zhangyingjie
 * @version $Id: v 0.1 2017年06月15日 15:17 zhangyingjie Exp $
 */
public abstract class AbstractIntegralMsgBusinessHandler implements IntegralMsgBusinessHandler {
    private Logger logger = LoggerFactory.getLogger(AbstractIntegralMsgBusinessHandler.class);
    @Resource
    private MessageService messageService;

    @Override
    public void handle(ISUserBehaviorReq request) {
        BaseResult msg = messageService.createMsg(RequestBuilder.buildT(toMsgCreateRequest(request)));
        if (msg.getErrcode() != 0) {
            logger.info(getMsgType().getDesc() + ":给userid:{},发送消息失败！", request.getUserId());
        }
    }

    abstract MsgCreateRequest toMsgCreateRequest(ISUserBehaviorReq request);

    abstract ISChannelType getMsgType();
}
